package com.spy.material.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.spy.common.utils.DateUtils;
import com.spy.material.vo.PurchaseOrderDetailVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.spy.material.mapper.PurchaseOrderDetailMapper;
import com.spy.material.domain.PurchaseOrderDetail;
import com.spy.material.service.IPurchaseOrderDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.Arrays;
/**
 * 采购明细Service业务层处理
 * 
 * @author twc
 * @date 2025-11-09
 */
@Service
public class PurchaseOrderDetailServiceImpl extends ServiceImpl<PurchaseOrderDetailMapper, PurchaseOrderDetail> implements IPurchaseOrderDetailService
{
    @Autowired
    private PurchaseOrderDetailMapper purchaseOrderDetailMapper;

    /**
     * 查询采购明细
     * 
     * @param id 采购明细主键
     * @return 采购明细
     */
    @Override
    public PurchaseOrderDetail selectPurchaseOrderDetailById(Long id)
    {
                return getById(id);
    }

    /**
     * 查询采购明细列表
     * 
     * @param purchaseOrderDetail 采购明细
     * @return 采购明细
     */
    @Override
    public List<PurchaseOrderDetail> selectPurchaseOrderDetailList(PurchaseOrderDetail purchaseOrderDetail)
    {
        return purchaseOrderDetailMapper.selectPurchaseOrderDetailList(purchaseOrderDetail);
    }

    /**
     * 新增采购明细
     * 
     * @param purchaseOrderDetail 采购明细
     * @return 结果
     */
    @Override
    public int insertPurchaseOrderDetail(PurchaseOrderDetail purchaseOrderDetail)
    {
        purchaseOrderDetail.setCreateTime(DateUtils.getNowDate());
                return save(purchaseOrderDetail) ? 1 : 0;
    }

    /**
     * 修改采购明细
     * 
     * @param purchaseOrderDetail 采购明细
     * @return 结果
     */
    @Override
    public int updatePurchaseOrderDetail(PurchaseOrderDetail purchaseOrderDetail)
    {
        purchaseOrderDetail.setUpdateTime(DateUtils.getNowDate());
                return updateById(purchaseOrderDetail) ? 1 : 0;
    }

    /**
     * 批量删除采购明细
     * 
     * @param ids 需要删除的采购明细主键
     * @return 结果
     */
    @Override
    public int deletePurchaseOrderDetailByIds(Long[] ids)
    {
                return removeByIds(Arrays.asList(ids)) ? 1 : 0;
    }

    /**
     * 删除采购明细信息
     * 
     * @param id 采购明细主键
     * @return 结果
     */
    @Override
    public int deletePurchaseOrderDetailById(Long id)
    {
                return removeById(id) ? 1 : 0;
    }

    @Override
    public List<PurchaseOrderDetailVO> getPurchaseOrderDetailByPurchaseOrderId(Long purchaseOrderId) {
        List<PurchaseOrderDetail> purchaseOrderDetailList = purchaseOrderDetailMapper.getPurchaseOrderDetailByPurchaseOrderId(purchaseOrderId);
        List<PurchaseOrderDetailVO> purchaseOrderDetailVOList = new ArrayList<>();
        for (PurchaseOrderDetail purchaseOrderDetail : purchaseOrderDetailList) {
            PurchaseOrderDetailVO purchaseOrderDetailVO = new PurchaseOrderDetailVO();
            BeanUtils.copyProperties(purchaseOrderDetail, purchaseOrderDetailVO);
            purchaseOrderDetailVOList.add(purchaseOrderDetailVO);
        }
        return purchaseOrderDetailVOList;
    }
}
